using System.Xml.Linq;
using System.Xml;
namespace XFControls.Utils
{
    public enum DebugType
    {
        ERROR,
        URL
    }
    public static class Debug
    {
        private static object _logInfoLock = new object();

        public static void log(string message, DebugType type)
        {
            #if(DEBUG)
            string debugFileName = XFControlUtils.GetCurrent_Directory() + "\\Debug.xml";
            XDocument db = null;
            if (System.IO.File.Exists(debugFileName))
            {
                try
                {
                    lock (_logInfoLock)
                        db = XDocument.Load(debugFileName);
                }
                catch (XmlException)
                {
                    db = new XDocument(
                        new XDeclaration("1.0", "utf-8", "yes"),
                        new XElement("debug"));
                }
            }
            else
                db = new XDocument(
                    new XDeclaration("1.0", "utf-8", "yes"),
                    new XElement("debug"));

            db.Root.Add(new XElement("message",
                new XAttribute("type", type.ToString()),
                new XAttribute("date", System.DateTime.Now.ToString()), message));

            lock (_logInfoLock)
                db.Save(debugFileName);
            #endif 
        }

    }
}
